package ink.lovejinhu.leetcode;

import java.util.HashMap;

/**
 * @author jinhu
 * created 2021-07-09 14:34
 */
public class Solution_0242 {
    /**
     * 字母异或和
     *
     * @param s
     * @param t
     * @return
     */
    public boolean isAnagram(String s, String t) {
        if (s.length() != t.length()) return false;
        char[] chars = s.toCharArray();
        char[] chart = t.toCharArray();
        HashMap<Character, Integer> var1 = new HashMap<>();
        for (int i = 0; i < s.length(); i++) {
            if (var1.containsKey(chars[i])) {
                Integer integer = var1.get(chars[i]);
                var1.put(chars[i], integer + 1);
            } else {
                var1.put(chars[i], 1);
            }
        }
        System.out.println(var1);
        for (int i = 0; i < s.length(); i++) {
            if (var1.containsKey(chart[i])) {
                Integer integer = var1.get(chart[i]);
                if (integer <= 0) {
                    return false;
                } else {
                    var1.put(chart[i], integer - 1);
                }
            } else {
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        String s = "aacc";
        String t = "ccac";
        Solution_0242 solution_0242 = new Solution_0242();
        solution_0242.isAnagram(s, t);
        //    System.out.println(solution_0242.isAnagram(s, t));
    }
}
